<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>AC娱乐砖石充值</title>
    <meta name=”viewport” content=”initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no”>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
    <script src="/static/js/jquery-3.3.1.min.js"></script>
    <style>
      body {
        padding: 3px;
      }
    </style>
  </head>
  <body>
    <div class="panel panel-primary">
      <div class="panel-heading">
        <h5>防骗声明</h5>
        <p>近期有以代充为借口向你索要密码的行为，实行诈骗，任何情况下不得将密码转述他人</p>
      </div>
      <div class="panel-body">
        <div class="form-horizontal">
          <div class="form-group">
            <label class="col-sm-2 control-label">QQ客服</label>
            <div class="col-sm-2">
              <input value="{$qqkf}" readonly class="form-control">
            </div>
            <label class="col-sm-2 control-label">微信客服</label>
            <div class="col-sm-2">
              <input value="{$wxkf}" readonly class="form-control">
            </div>
          </div>
    
          <div class="form-group">
            <label for="zhanghao" class="col-sm-2 control-label">充值账号</label>
            <div class="col-sm-2">
              <input value="{$loginUser}" readonly class="form-control" id="zhanghao" placeholder="请输入充值账号">
            </div>
            <label for="money" class="col-sm-2 control-label">充值金额</label>
            <div class="col-sm-2">
              <input type="text" value="{$money}" class="form-control" id="money" placeholder="请输入充值金额">
            </div>
          </div>

          <div class="form-group">
            <label for="type" class="col-sm-2 control-label">充值方式</label>
            <div class="col-sm-2">
              <select class="form-control" name="type">
                <option value="1">微信</option>
                <option value="2">支付宝</option>
                <option value="3">银行卡</option>
              </select>
            </div>
          </div>

          <div class="form-group" id="wx">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-10">
              <div class="row">
                <div class="col-xs-6 col-md-3">
                  <div class="thumbnail">
                    <img src="{$wxcode ?? ''}" alt="微信二维码">
                    <div class="caption">
                      <p>微信账号: {$wxzh ?? ''}</p>
                      <p>请扫码转账或者添加好友转账</p>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div class="form-group" id="zfb">
            <label class="col-sm-2 control-label"></label>
            <div class="col-sm-10">
              <div class="row">
                <div class="col-xs-6 col-md-3">
                  <div class="thumbnail">
                    <img src="{$zfbcode ?? ''}" alt="微信二维码">
                    <div class="caption">
                      <p>支付宝账号: {$zfbzh ?? ''}</p>
                      <p>请扫码转账或者添加好友转账</p>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div id="bank">
            <div class="form-group">
              <label class="col-sm-2 control-label">开户行</label>
              <div class="col-sm-3">
                <input type="text" readonly value="{$bank_name}" class="form-control">
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">银行卡账号</label>
              <div class="col-sm-3">
                <input type="text" readonly value="{$bank_account}" class="form-control">
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">持卡人姓名</label>
              <div class="col-sm-3">
                <input type="text" readonly value="{$bank_people}" class="form-control">
              </div>
            </div>
          </div>

          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
              <button type="submit" class="btn btn-primary btn-lg btn-block" onclick="submitForm()">提交充值</button>
              <!-- <button type="submit" class="btn btn-default" onclick="exit()">退出</button> -->
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>

  <script type="text/javascript">
    $(function() {
      onListeningType()
      $('#wx').css('display', 'block')
      $('#zfb').css('display', 'none')
      $('#bank').css('display', 'none')
    })

    var submitData = {
      type: 1,
      money: 0,
      user: null
    }

    var onListeningType = function () {
      $('[name=type]').change(function(res) {
        var val = parseInt($('[name=type]').val())
        submitData.type = val

        if (val === 1) {
          $('#wx').css('display', 'block')
          $('#zfb').css('display', 'none')
          $('#bank').css('display', 'none')
        } else if (val === 2) {
          $('#wx').css('display', 'none')
          $('#zfb').css('display', 'block')
          $('#bank').css('display', 'none')
        } else if (val === 3) {
          $('#wx').css('display', 'none')
          $('#zfb').css('display', 'none')
          $('#bank').css('display', 'block')
        }
      })
    }

    var formVerify = function () {
      // 赋值
      submitData.user = $('#zhanghao').val()
      submitData.money = parseFloat($('#money').val())

      if (submitData.user == null) {
        alert('账号不能为空');
        return false
      }

      if (submitData.money <= 0 ||
        submitData.money == null ||
        submitData.money == '' ||
        submitData.money == NaN) {
        alert('请输入正确的金额');
        return false
      }

      if (submitData.type == 0) {
        alert('请选择支付方式')
        return false
      }

      return true
    }

    var submitForm = function () {
      if (!formVerify()) return false
      var btn = $('[type=submit]')
      btn.attr('disabled', 'disabled')
      btn.text('充值中，请等待...')
      $.post('{:url("rechargeApi")}', submitData, (res) => {
        btn.removeAttr('disabled')
        btn.text('提交充值')
        alert(res.msg)
      })
    }

    var exit = function () {
      // parent.postMessage({close: true, msg: '退出充值'}, "*")
    }
  </script>
</html>
